<template>
  <div class="app-container">
    <el-form ref="form2" :model="form2" :rules="rules2" label-width="110px">
      <el-form-item label="佣金计算方式" prop="commision_type">
        <el-radio-group v-model="form2.commision_type">
          <el-radio :label="1">利润百分比</el-radio>
          <el-radio :label="2">销售额百分比</el-radio>
          <el-radio :label="3">指定金额</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="直属" prop="commision_rate1">
        <el-input-number
          v-model="form2.commision_rate1"
          :precision="2"
          :step="1"
          :min="0"
          :max="100"
          placeholder="直属客户佣金比例"
        >
        </el-input-number>
      </el-form-item>
      <el-form-item label="间接" prop="commision_rate2">
        <el-input-number
          v-model="form2.commision_rate2"
          :precision="2"
          :step="1"
          :min="0"
          :max="100"
          placeholder="间接客户佣金比例"
        >
        </el-input-number>
      </el-form-item>
      <el-form-item prop="commision_rate2">
        <!-- v-hasPermi="['api:v1:updateDefaultCommisionRule']" -->
        <el-button type="primary" @click="updateDefaultCommision"
          >确 定</el-button
        >
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import {
  getDefaultCommisionRule,
  updateDefaultCommisionRule,
} from "@/api/member/moviesCommission";
export default {
  name: "merchantmoviesCommissionindex",
  data() {
    return {
      form2: {
        commision_type: null,
        commision_rate1: null,
        commision_rate2: null,
      },
      rules2: {
        commision_type: [
          { required: true, message: "请选择计算方式", trigger: "blur" },
        ],
        commision_rate1: [
          { required: true, message: "请输入直属比例或佣金", trigger: "blur" },
        ],
        commision_rate2: [
          { required: true, message: "请输入间接比例或佣金", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getDefaultCommision();
  },
  methods: {
    getDefaultCommision() {
      getDefaultCommisionRule().then((response) => {
        if (response.data) {
          this.form2 = response.data;
          this.form2.commision_rate1 = +this.form2.commision_rate1;
          this.form2.commision_rate2 = +this.form2.commision_rate2;
        }
      });
    },
    updateDefaultCommision() {
      this.$refs["form2"].validate((valid) => {
        if (valid) {
          updateDefaultCommisionRule(this.form2).then((response) => {
            this.$modal.msgSuccess("修改成功");
            this.getDefaultCommision();
          });
        }
      });
    },
  },
};
</script>

<style></style>
